package com.fone.player.view;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.fone.player.R;
import com.fone.player.util.ScreenUtil;

public class LocalDeleteMediaDialog {

	private IDeleteListener Listener;

	public void setListener(IDeleteListener listener) {

		Listener = listener;
	}

	public LocalDeleteMediaDialog(Activity activity) {
		creatDeleteMediaDialog(activity, null);
	}

	public LocalDeleteMediaDialog(Activity activity, String message) {
		creatDeleteMediaDialog(activity, message);
	}

	public void creatDeleteMediaDialog(Activity activity, String message) {

		View Local_Delete_Media_View = LayoutInflater.from(activity).inflate(
				R.layout.local_delete_media_dialog, null);
		TextView tv_desc = (TextView) Local_Delete_Media_View
				.findViewById(R.id.tv_local_delete_desc);
		if (!TextUtils.isEmpty(message)) {
			tv_desc.setText(message);
		}
		final CustomDialog dialog = new CustomDialog((Context) activity,
				Local_Delete_Media_View);
		dialog.setCanceledOnTouchOutside(false);

		dialog.show();

		Local_Delete_Media_View.setMinimumWidth((int) (ScreenUtil
				.getScreenWidthPix(activity) * 0.8));// 设置dialog的宽度

		Button deleteSureBtn = (Button) Local_Delete_Media_View
				.findViewById(R.id.btn_delete_sure);
		deleteSureBtn.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				if (Listener != null) {
					Listener.delete();
					dialog.dismiss();
				}

			}
		});

		Button deleteCancelBtn = (Button) Local_Delete_Media_View
				.findViewById(R.id.btn_delete_cancel);
		deleteCancelBtn.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				dialog.dismiss();
			}
		});

	}

	public interface IDeleteListener {
		void delete();
	}
}
